﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace Congducsan
{
    public partial class FrmDatyeu : Form
    {
        public FrmDatyeu()
        {
            InitializeComponent();
        }

        private void FrmDatyeu_FormClosing(object sender, FormClosingEventArgs e)
        {
            DradApplication.DradApp.FormMain.Show();
        }

        private void txtGiaip1_CheckedChanged(object sender, EventArgs e)
        {
            if (txtGiaip1.Checked)
            {
                pictureBox1.Image = Congducsan.Properties.Resources.Datyeu1;
                Command3.Enabled = false;
                txtDocnenm1.Enabled = false;
                txtDocnenm2.Enabled = false;
                txtCutram.Enabled = false;
                txtVaiT.Enabled = false;
                txtVaiP.Enabled = false;
            }
        }

        private void txtGiaip2_CheckedChanged(object sender, EventArgs e)
        {
            if (txtGiaip2.Checked)
            {
                pictureBox1.Image = Congducsan.Properties.Resources.Datyeu2;
                Command3.Enabled = true;
                txtDocnenm1.Enabled = true;
                txtDocnenm2.Enabled = true;
                txtCutram.Enabled = true;
                txtVaiT.Enabled = true;
                txtVaiP.Enabled = true;
            }
        }

        private void FrmDatyeu_Resize(object sender, EventArgs e)
        {
            this.Size = new Size(634, 403);
        }

        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmDatyeu_Load(object sender, EventArgs e)
        {
            loadSettingReg();
        }
        private void saveSettingReg()
        {
            RegistryKey regKey = Registry.CurrentUser;
            regKey = regKey.CreateSubKey("Software\\HaithanhSoft\\Drad2012\\Congducsan");
            RegistryKey regTmp = Registry.CurrentUser;
            regTmp=regTmp.CreateSubKey("Software\\HaithanhSoft\\Drad2012\\Congducsan");
            string tmp = regTmp.GetValue("KtDatyeu").ToString();
            string[] Values1 = tmp.Split('\t');
            string Values = "";
           
            Values = Values1[0]; //0
            Values = Values +"\t"+ txtGiaip1.Checked.ToString(); //1
            Values = Values +"\t"+ Values1[2];  //2
            Values = Values +"\t"+ txtGiaip2.Checked.ToString();  //3
            Values = Values +"\t"+ txtDocnenm1.Text; //4
            Values = Values +"\t"+ txtDocnenm2.Text; //5
            Values = Values +"\t"+ txtCutram.Checked.ToString();  //6
            Values = Values +"\t"+ txtLopcat.Text;  //7
            Values = Values +"\t"+ txtVaidiaL.Text; //8
            Values = Values +"\t"+ txtMatdococ.Text; //9
            regKey.SetValue("KtDatYeu", Values);
            regTmp.Close();
            regKey.Close();
        }
        private void loadSettingReg()
        {
            RegistryKey regKey = Registry.CurrentUser;
            RegistryKey testKey = regKey.OpenSubKey("Software\\HaithanhSoft\\Drad2012\\Congducsan");
            if (testKey != null)
            {
                regKey = regKey.CreateSubKey("Software\\HaithanhSoft\\Drad2012\\Congducsan");
                string str = regKey.GetValue("KtDatyeu").ToString();
                string[] STR = str.Split('\t');
                int i = 0;
                i++;
                txtGiaip1.Checked=bool.Parse(STR[i++]);//1
               // Values1(2);//2
                i++;
                txtGiaip2.Checked = bool.Parse(STR[i++]);//3
                txtDocnenm1.Text=STR[i++];//4
                txtDocnenm2.Text = STR[i++];//5
                txtCutram.Checked = bool.Parse(STR[i++]);//6
                txtLopcat.Text = STR[i++];//7
                txtVaidiaL.Text = STR[i++];//8
                txtMatdococ.Text = STR[i++];//9
              
            }
        }

        private void FrmDatyeu_FormClosed(object sender, FormClosedEventArgs e)
        {
            saveSettingReg();
        }
    }
}
